// Marty Stepp, CSE 142, Winter 2008 // // This program draws lines and boxes of stars. // This version uses parameters to remove redundancy in // the code to print the stars and boxes. public class Stars1 { public static void main(String[] args) { drawLineOfStars(13); drawLineOfStars(7); drawLineOfStars(35); System.out.println(); drawBox(10, 3); drawBox(5, 4); drawBox(35, 20); } // Prints a line containing the given number of stars. // For example, drawLineOfStars(8) prints 8 stars. public static void drawLineOfStars(int count) { for (int i = 1; i <= count; i++) { System.out.print("*"); } System.out.println(); } // Prints a hollow box of the given width and height, wrapped in *s. // For example, drawBox(7, 5) makes a 7x5 box wrapped in *s. public static void drawBox(int width, int height) { // top line drawLineOfStars(width); // middle hollow section for (int line = 1; line <= height - 2; line++) { System.out.print("*"); for (int i = 1; i <= width - 2; i++) { System.out.print(" "); } System.out.println("*"); // end the line } // bottom line drawLineOfStars(width); } }